package cn.cycleif.app.service;

import cn.cycleif.app.mapper.MenuMapper;
import cn.cycleif.entity.Menu;
import cn.cycleif.util.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Date: 25/1/21-16:47
 * @Desc:
 */
@Service
public class MenuService extends ServiceImpl<MenuMapper, Menu> {

  @Autowired
  private MenuMapper menuMapper;

  public R<List<Menu>> getMenusByRoleId(Integer roleId) {
    List<Menu> list = menuMapper.findMenuListByRoleId(roleId);
    return R.success(list);
  }

  public List<Menu> selectByRanks(Integer ranks) {
    LambdaQueryWrapper<Menu> wrapper = new LambdaQueryWrapper<>();
    wrapper.le(Menu::getRequiredRanks, ranks);
    return menuMapper.selectList(wrapper);
  }
}
